<template>
  <div>
    <v-alert :type="type" v-if=" alert != '' ">
      {{ alert }}
    </v-alert>
    <v-overlay color="#fff" :value="overlay">

    <v-progress-circular
      :size="70"
      :width="7"
      color="green"
      indeterminate
    ></v-progress-circular>
    </v-overlay>
  </div>
</template>
<script>
import { oauthlogin } from './../../libs/api_v1'
import { domain, search } from './../../libs/api'
import { setTimeout } from 'timers';
export default {
  data:()=>({
    type:'',
    alert:'',
    overlay:true
  }),
  name:"OauthWechat",
  created: function(){
    var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
    if(is_weixin){
      this.type = 'success'
      this.alert = ""
      console.log("在微信中")
      var initURL
      if(search("initURL")){
        initURL = decodeURIComponent(search("initURL"))
      }else{
        initURL = "/"
      }
      oauthlogin(initURL, "auth")
      .then((resp)=>{
          var res = resp.data;
          if (res.code == 1){
            setTimeout(()=>{ 
              window.location.href = res.data.uri 
            },100)
          }
          this.snackbar = {
              isOpen: true,
              text: res.msg
          }
      })
    }else{
      console.log("不是微信")
      this.type = 'info'
      this.alert = "错误，须在微信内才可使用授权登陆"
      setTimeout(()=>{ 
          window.location.href = "/auth/login"
        },100) 
    }
  }
}
</script>